package com.sssre.lttcloud.framework.controller;

import com.sssre.lttcloud.framework.service.PerformanceMonitorService;
import com.sssre.lttcloud.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 性能监测控制器
 */
@RestController
@RequestMapping("/performance")
@CrossOrigin
public class PerformanceController {

    @Autowired
    private PerformanceMonitorService performanceMonitorService;

    /**
     * 获取性能统计
     */
    @GetMapping("/stats")
    public Result getPerformanceStats() {
        return performanceMonitorService.getPerformanceStats();
    }

    /**
     * 获取方法调用历史
     */
    @GetMapping("/history/{methodName}")
    public Result getMethodHistory(@PathVariable String methodName, 
                                 @RequestParam(defaultValue = "10") int limit) {
        return performanceMonitorService.getMethodHistory(methodName, limit);
    }

    /**
     * 获取慢查询列表
     */
    @GetMapping("/slow")
    public Result getSlowQueries(@RequestParam(defaultValue = "1000") long threshold) {
        return performanceMonitorService.getSlowQueries(threshold);
    }

    /**
     * 清理历史数据
     */
    @DeleteMapping("/history")
    public Result clearHistoryData(@RequestParam(defaultValue = "7") int days) {
        return performanceMonitorService.clearHistoryData(days);
    }
} 